# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.sites.models import Site
from django.contrib.auth.models import User

from pennypress.apps.categories.models import CategoryBase, SectionBase
from pennypress.base.managers import CurrentSitePublishedManager


STATUS = (
    ('D', 'DRAFT'),
    ('R', 'READY FOR EDITING'),
    ('E', 'READY TO PUBLISH'),
    ('P', 'PUBLISHED'),
    ('S', 'STATIC'),
    ('U', 'REJECTED'),
)

class AuthorTimeCommentBase(models.Model):
    authors = models.ManyToManyField(User, verbose_name=_('Authors'),\
        blank=True, null=True)
    off_author = models.CharField(_('One off author(s)'), max_length=200,\
        blank=True)
    publish_date = models.DateTimeField(_('Time to Publish'))
    update_date  = models.DateTimeField(_('Update Date'),\
        help_text=_("The update date to display to the user"), blank=True)
    modified_date = models.DateTimeField(_("Date Modified"), auto_now=True,\
        blank=True, editable=False)
    comments = models.BooleanField(_('Enable Comments?'), default=True)
    site = models.ManyToManyField(Site, verbose_name=_('Sites'))
    status = models.CharField(_('Published Status'), max_length=1,\
        choices=STATUS, default="D")
                                    
    class Meta:
        ordering = ['-publish_date']
        get_latest_by = 'publish_date'
        abstract = True

class PennyPressBase(CategoryBase, SectionBase, AuthorTimeCommentBase):
    """
    A base class that allows all PennyPress to work with the same set of 
    parameters
    """
    
    objects = models.Manager()
    published_on_site = CurrentSitePublishedManager('site')
    
    class Meta(AuthorTimeCommentBase.Meta):
        abstract = True
